#include <bits/stdc++.h>
using namespace std;
const int maxn = 100+5;
int G[maxn][maxn], d[maxn][maxn], n, m;

inline bool in(int i, int j){return i>=0 && i<n && j>=0 && j<m;}

int DP(int i, int j){
    if(d[i][j] > -1) return d[i][j];
    d[i][j] = 1;
    for (int dr = -1; dr <= 1; ++dr) {
        for (int dc = -1; dc <= 1; ++dc) if(!dr || !dc){
            if(in(i+dr, j+dc) && G[i+dr][j+dc] < G[i][j])
                d[i][j] = max(d[i][j], DP(i+dr, j+dc)+ 1);
        }
    }
    return d[i][j];
}
int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    cin >> n >> m;
    memset(d, -1, sizeof(d));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> G[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            ans = max(ans, DP(i,j));
        }
    }
    cout << ans;
    return 0;
}